package cn.fcj.f20240328.fsocket.base;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;

/**
 * @项目名称:FSocket
 * @功能描述:socket事件接口
 * @开发　者:mochhk
 * @邮　　箱:mochhk@163.com
 * @CreateDate:2024/4/5 13:31
 */
public interface  ISocketEventHandler {
    /**
     * 发送数据
     * @param key
     * @param msg
     * @return
     * @throws IOException
     */
    public  ByteBuffer  sendData(SelectionKey key, byte[] msg)throws IOException;
    /**
     * 接收数据
     * @param key
     * @throws IOException
     */
    public void receiveDataForChannel(SelectionKey key) throws IOException;

    /**
     * socket 异常处理
     * @param e
     * @param errorCode
     * @param key
     */
    public void exceptionHandler(Exception e, FBaseNIOSocket.ErrorCode errorCode, SelectionKey key);

    /**
     * 连接成功或有新的连接
     * @param key
     * @throws IOException
     */
    public void onConnected(SelectionKey key)throws IOException;
}
